<template>
  <view class="authorization">
    <block v-if="!isShow"><slot></slot></block>
    <!-- 授权界面 -->
    <view v-if="isShow" @tap="toAuthorize" style=""></view>
  </view>
</template>

<script>
//权限验证
import { mapState, mapActions, mapMutations } from "vuex";
import request from "../../utils/request";
import {getToken} from '../../utils/token';

export default {
  props: ["isBusiness"],
  data() {
    return {
      msg: "Hello33333 world!",
    };
  },
  computed: {
    // 计算属性的 getter
    ...mapState({
      user: (state) => {
        console.log(state, "sssssssss");
        return state.user;
      },
    }),
    isShow: function () {
      // `this` 指向 vm 实例
      console.log(
        this.user,
        this.isBusiness != null && this.user.avatar == false,
        "thisuuu"
      );
      if (this.uisBusiness != null && this.user.avatar == false) return true;

      // if (avatar == false) {
      //   return false;
      // }

      return false;
    },
  },
  watch: {
    isShow: function (newQuestion, oldQuestion) {
      console.log(newQuestion, "userinfothis.setNickName(nickName)");
      if (newQuestion) {
      }
    },
  },
  mounted() {
    console.log("userinfo5");
    console.log("哈哈哈哈哈哈", this.isShow, getToken());
    if (!this.isShow) {
      console.log("userinfo4");
      console.log(this, "userinfothis.setNickName(nickName)");


      wx.getUserInfo({
        success: function (res) {
          let userInfo = res.userInfo;
         let nickName = userInfo.nickName;
         let avatarUrl = userInfo.avatarUrl;
          let gender = userInfo.gender; //性别 0：未知、1：男、2：女
          let province = userInfo.province;
          let city = userInfo.city;
          let country = userInfo.country;
          console.log("呵呵呵呵呵呵呵额呵呵");
          console.log(this, "userinfothis.setNickName(nickName)");
          request("post", "/api/weixin/update_user_info.htm", {
            openid: getToken(),
            nickName: nickName,
            name: nickName,
            avatarUrl: avatarUrl,
          });

        },fail: function(res) {
          console.log("getUserInfo失败 ");
        }
      });

    }
  },
  created() {
    // console.log(user, "333");
  },
  methods: {
    ...mapMutations("user", ["setNickName", "setAvatar"]),

    toAuthorize() {
      console.log("444");
      const auths = wx.getSetting;

      console.log(auths, "444");
    },
  },
};
</script>
